public class hw6 {
    public static void main(String[] args) {


        for (int i = 1; i <= 999999; i++) {
            int count = 0;
            int sum = 0;
            int tmp = i;
            while (tmp != 0) {

                tmp /= 10;
                count++;
            }
            tmp = i;

            for (int j = 0; j < count; j++) {
                sum += Math.pow(tmp % 10, count);
                tmp /= 10;
            }
            if (sum == i) {
                System.out.println(i);
            }
        }

    }
}

